const app =getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:-1,
    info:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id:options.id
    })
  },


  onShow: function () {
    this.getInfo()
  },
  getInfo(){
    let token = wx.getStorageSync('token')
    var that = this;
    that.data.page = 1;
    wx.showLoading();
    app.util.request({
      url: app.do('index/OrderInfo'),
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        // m: app.siteInfo.m,
        token: token,
        order_id: that.data.id,
      },
      success: function (res) {
        wx.hideLoading()
        if (res.data.code == "0000") {
          that.setData({
            info:res.data.data.order
          })
        } else if (res.data.code == "2001") {
          wx.navigateTo({
            url: '../auth/auth',
          })
        } else {
          var text = res.data.message;
          wx.showToast({
            title: text,
            icon: 'none',
            duration: 2000,
          })
        }
      },
      fail: function (res) {
        wx.hideLoading()
        var text = res.data.message;
        wx.showToast({
          title: text,
          icon: 'none',
          duration: 2000,
        })
      }
    })
  },

  wuliu(e){
    wx.navigateTo({
      url: '../information/information?orderId='+this.data.info.order_id,
    })
  },

  refirm(e){
   
    let token = wx.getStorageSync('token')
    var that = this;
    wx.showModal({
      title: '',
      content: '是否确认收货？',
      success (res) {
        if (res.confirm) {
         
    that.data.page = 1;
    wx.showLoading();
    app.util.request({
      url: app.do('index/OrderConfirm'),
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        token: token,
        order_id: that.data.info.order_id
      },
      success: function (res) {
        wx.hideLoading()
        if (res.data.code == "0000") {
          wx.showToast({
            title: '确认收货成功',
          });
          setTimeout(() => {
            wx.navigateTo({
              url: '../orderList/orderList',
            })
          }, 2000);
         
        } else if (res.data.code == "2001") {
          wx.navigateTo({
            url: '../auth/auth',
          })
        } else {
          var text = res.data.message;
          wx.showToast({
            title: text,
            icon: 'none',
            duration: 2000,
          })
        }
      },
      fail: function (res) {
        wx.hideLoading()
        var text = res.data.message;
        wx.showToast({
          title: text,
          icon: 'none',
          duration: 2000,
        })
      }
    })
        } else if (res.cancel) {
        }
      }
    })

  },


  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})